﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using Refactored.Controllers;
using Refactored.Models;

namespace NetBooksWeb.Controllers
{
    public class ViewController : ApiController
    {
        private BookContext db = new BookContext();
        
        // GET api/View/5
        public IEnumerable<Book> GetView(string view)
        {
            if (view.Equals("By Author"))
                return db.Books.OrderBy(b => b.Author).ToList();
            if (view.Equals("By Genre"))
                return db.Books.OrderBy(b => b.Genre).ToList();
            if (view.Equals("By Title"))
                return db.Books.OrderBy(b => b.Title).ToList();
            if (view.Equals("My Books"))
                //return db.Users.First(u => u.UserName.Equals(User.Identity.Name)).Books;
                return db.Books;
            return new List<Book>();
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}